#include <iostream>
#include "mei_file.h"
#include "error_no.h"

int main(int argc, char *argv[]) {
    if (argc != 5) {
        std::cout << "参数数量错误，应传入四个参数：" << std::endl;
        std::cout << "第一个参数为操作类型，支持：send_file、recv_file；" << std::endl;
        std::cout << "第二个参数为文件路径；" << std::endl;
        std::cout << "第三个参数为host；" << std::endl;
        std::cout << "第四个参数为port；" << std::endl;
        return WRONG_ARGS_COUNT;
    }

    std::string operator_type = argv[1];
    fileFunPtr funPtr;
    if (operator_type == "send_file") {
        funPtr = sendFile;
    } else if (operator_type == "recv_file") {
        funPtr = recvFile;
    } else {
        std::cout << "错误的参数，第一个参数只支持：send_file、recv_file" << std::endl;
        return WRONG_OPERATOR_TYPE;
    }

    int port = 0;
    try {
        port = std::stoi(argv[4]);
    } catch (const std::exception &e) {
        std::cout << "参数port：无效的输入: " << e.what() << std::endl;
        return WRONG_PORT;
    }
    try {
        return funPtr(argv[2], argv[3], port);
    } catch (int err_no) {
        return err_no;
    }
}